/*
 * gcourse.cc
 *
 *  Created on: Sep 25, 2012
 *      Author: shaohong
 */

#include "gcourse.hh"
using namespace std;

GolfCourse::GolfCourse(
		const std::string& name,
		const std::vector<GolfHole>& holes,
		const std::map<std::pair<Gender, TeeColor>, std::pair<double, size_t> >& difficulty) {

	this->name = name;
	this->holes = holes;
	this->difficulty = difficulty;

}

const std::string& GolfCourse::getName() const {
	return name;

}


const std::vector<GolfHole>& GolfCourse::getHoles() const {
	return holes;
}

size_t GolfCourse::getPar() const {
//    * The course par is calculated by accumulating (hint) all the par values
//    * of the golf course's golf holes.
	size_t parValue = 0;
	for(size_t i=0; i<holes.size(); i++) {
		parValue += holes[i].getPar();
	}

	return parValue;
}

const std::pair<double, size_t>& GolfCourse::getDifficulty(Gender gender, TeeColor teeColor) const {
	pair<Gender, TeeColor> genderTeePair(gender, teeColor);
	map<pair<Gender, TeeColor>, pair<double, size_t> >::const_iterator itr = difficulty.find(genderTeePair);

	return itr->second;
}


std::istream& operator >> (std::istream& in, GolfCourse& course) {
//	<Golf course name>
//	<Hole 1 Par> <Hole 1 HCP>
//	<Hole 2 Par> <Hole 2 HCP>
//	.
//	.
//	.
//	<Hole 18 par> <Hole 18 HCP>
//	<Men red tee CR> <Men red tee slope>
//	<Men blue tee CR> <Men blue tee slope>
//	<Men yellow tee CR> <Men yellow tee slope>
//	<Men white tee CR> <Men white tee slope>
//	<Women red tee CR> <Women red tee slope>
//	<Women blue tee CR> <Women blue tee slope>
//	<Women yellow tee CR> <Women yellow tee slope>
//	<Women white tee CR> <Women white tee slope>

	char line[256];
	in.getline(line, sizeof(line));

	course.name = string(line);

	for (int i = 0; i < 18; i++) {
		GolfHole hole;
		in >> hole;
		course.holes.push_back(hole);
	}

	double cr;
	size_t slope;
	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(MALE,RED), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(MALE,BLUE), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(MALE,YELLOW), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(MALE,WHITE), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(FEMALE,RED), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(FEMALE,BLUE), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(FEMALE,YELLOW), make_pair(cr, slope)));

	in >> cr >> slope;
	course.difficulty.insert(make_pair(make_pair(FEMALE,WHITE), make_pair(cr, slope)));

	return in;
}
